package com.example.tests;

import static org.testng.Assert.assertEquals;
import com.example.utils.SortedListOf;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import org.testng.annotations.Test;

public class ContactModificationTest extends TestBase {
	@Test(dataProvider = "randomValidGroupGenegator")
	public void ContactModification() throws Exception {

		app.navigatiTo().mainPage();
		// save state

		SortedListOf<ContactData> oldList = app.getContactHelper().getContacts();
		Random rnd = new Random();
		int index = rnd.nextInt(oldList.size() - 1);

		// actions

		app.getContactHelper().editConact(index);

		ContactData contact = new ContactData();
		contact.firstname = "some name";
		app.getContactHelper().fillContactForm(contact);

		app.getContactHelper().submitModifContact();
		app.navigatiTo().mainPage();
		// new state
		List<ContactData> newList = app.getContactHelper().getContacts();
		// compare old vs new
		oldList.remove(index);
		oldList.add(contact);
		Collections.sort(oldList);
		assertEquals(newList, oldList);
	}

}
